import { useToast } from 'vue-toastification'
import router from './router'
import { useAppStore } from './stores/app'

router.beforeEach((to, from, next) => {
  const appStore = useAppStore()
  const toast = useToast()
  if (!appStore.loaded) {
    appStore
      .loadApp()
      .then(() => {
        document.title = appStore.name
      })
      .catch(() => {
        toast.error('加载应用信息失败')
      })
      .finally(() => {
        next()
      })
  } else {
    document.title = appStore.name
    next()
  }
})
